//
//  LGClassTabAndColViewController+Collection.m
//  LuxuryGoods
//
//  Created by 宋柯 on 2018/5/22.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGClassTabAndColViewController+Collection.h"
#import "BrandCollectionViewCell.h"
#import "LGGoodsModel.h"
#import "LGCateModel.h"

@implementation LGClassTabAndColViewController (Collection)

- (void)makeCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //设置滑动方向
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    flowLayout.minimumLineSpacing = 5;
    
    flowLayout.minimumInteritemSpacing = 5;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(120, 0, SCREEN_WIDTH - 120, SCREEN_HEIGHT - NAVIGATOR_HEIGHT - TABBAR_HEIGHT) collectionViewLayout:flowLayout];
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    self.collectionView.delegate = self;
    
    self.collectionView.dataSource = self;
    
    self.collectionView.scrollEnabled = YES;
    
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"BrandCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"BrandCollectionViewCell"];

}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.productDataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"BrandCollectionViewCell";
    
    BrandCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    
//    [cell setBrandCell];
    
    LGCateModel *model = self.productDataArray[indexPath.row];
    
    [cell.brandImageView yy_setImageWithURL:[NSURL URLWithString:model.cate_img] options:YYWebImageOptionProgressive];
    
    cell.brandName.text = model.cate_name;
    
    
    return  cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemWidth = ceilf(self.collectionView.width - 10 * 3)/3;
    
    return  CGSizeMake(itemWidth, itemWidth + 10);
}

#pragma mark  定义整个CollectionViewCell的四个边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 5, 5, 5);//（上、左、下、右）
}


@end
